package com.cskaoyan.controller.backStage;

import com.cskaoyan.model.Order;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.bo.OrderDetailBO;
import com.cskaoyan.model.bo.OrderListBO;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.model.vo.DataVO;
import com.cskaoyan.model.vo.ShipChannelVO;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: OrderController
 * @Description: TODO 订单管理模块
 * @Author:zhoukang
 * @Date: 2022/5/5 17:41
 * @Version: 1.0
 **/
@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;


    /**
     * @author: zhoukang
     * @description: TODO 查询订单列表
     * @date: 2022/5/6 21:09
     */
    @RequiresPermissions("admin:order:list")
    @RequestMapping("list")
    public BaseRespVO orderList(BaseParamBO param, OrderListBO orderListBO){
        DataVO<Order> orderDataVO = orderService.query(param,orderListBO);
        return BaseRespVO.ok(orderDataVO);
    }

    /**
     * @author: zhoukang
     * @description: TODO 订单详情
     * @date: 2022/5/7 0:00
     */
    @RequiresPermissions("admin:order:detail")
    @RequestMapping("detail")
    public BaseRespVO orderDetail(String id){
        OrderDetailBO orderDetailBO ;
        Integer i;
        try {
                i = Integer.parseInt(id);
            orderDetailBO = orderService.queryOrderDetail(i);
        }catch (Exception e){
            return BaseRespVO.parameterError("参数值不对");
        }

         return BaseRespVO.ok(orderDetailBO);
    }

    /**
     * @author: zhoukang
     * @description: TODO 订单退款(order_status:202-->203)
     * @date: 2022/5/7 8:47
     */
    @RequiresPermissions("admin:order:refund")
    @PostMapping("refund")
    public BaseRespVO refund(@RequestBody Map order){
        orderService.updateRefund(order);
        return BaseRespVO.ok(null);
    }

    /**
     * @author: zhoukang
     * @description: TODO 订单发货
     * @date: 2022/5/7 9:03
     */
    @RequiresPermissions("admin:order:ship")
    @RequestMapping("ship")
    public BaseRespVO ship(@RequestBody Map order){
        orderService.updateShip(order);
        return BaseRespVO.ok(null);
    }

    /**
     * @author: zhoukang
     * @description: TODO 逻辑删除
     * @date: 2022/5/7 9:19
     */
    @RequiresPermissions("admin:order:delete")
    @RequestMapping("delete")
    public BaseRespVO delete(@RequestBody Map orderId){
        //101,102,103可以进行删除,其他的都不可进行删除操作
        boolean delete = orderService.delete(orderId);
        if (delete==false){
            return BaseRespVO.parameterError("该订单不可删除");
        }
        return BaseRespVO.ok(null);
    }
    @RequiresPermissions("admin:order:channel")
    @RequestMapping("channel")
    public BaseRespVO channel(){
        List<ShipChannelVO> list = new ArrayList<>();
        list.add(new ShipChannelVO("YTO", "圆通快递"));
        list.add(new ShipChannelVO("YD", "韵达快递"));
        list.add(new ShipChannelVO("YZPY", "邮政快递包裹"));
        list.add(new ShipChannelVO("EMS", "EMS"));
        list.add(new ShipChannelVO("DBL", "德邦快递"));
        list.add(new ShipChannelVO("FAST", "快捷快递"));
        list.add(new ShipChannelVO("ZJS", "宅急送"));
        list.add(new ShipChannelVO("TNT", "TNT快递"));
        list.add(new ShipChannelVO("UPS", "UPS"));
        list.add(new ShipChannelVO("DHL", "DHL"));
        list.add(new ShipChannelVO("FEDEX", "FEDEX联邦(国内件)"));
        list.add(new ShipChannelVO("FEDEX_GJ", "FEDEX联邦(国际件)"));
        return BaseRespVO.ok(list);
    }

}
